package com.bluefish.bltuan.tools.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public final class AnnotationUtil {

	
	private AnnotationUtil() {
		
	}
	
	/**
	 * get all method with the given annotation presented.
	 * This includes public, protected, default (package) access, and private methods, 
	 * but excludes inherited methods
	 * 
	 * @param targetClass target class object
	 * @param annotation the annotation presented on method
	 * @return list of method has the given annotation
	 */
	public static List<Method> getAnnotatedMethods(
			Class<?> targetClass, Class<? extends Annotation> annotation) {
		List<Method> result = new ArrayList<Method>();
		
		//original
		//Method[] mtds = targetClass.getDeclaredMethods();
		
		//change to get method from the class extends
		Method[] mtds = targetClass.getMethods();
		
		for(Method mtd : mtds) {
			if(mtd.isAnnotationPresent(annotation)) {
				result.add(mtd);
			}
		}
		return result;
	}

	

}
